<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone = no">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>Title</title>

<!--        <script type="text/javascript" src="hYi-sdk.js"></script>-->
    <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/751496032/hYi-sdk@1.0.2/hYi-sdk.js"></script>
    <script type="text/javascript">

        function test1() {
            takeNativeActionWithCallback("login", {
                targetClassName: "com.xxx"
            }, {
                success: function (res) {
                    console.log("success res: " + JSON.stringify(res))
                },
                fail: function (res) {
                    console.log("fail res: " + JSON.stringify(res))
                },
                complete: function () {
                    console.log("complete res ")

                }
            })
        }


        function login() {
            console.log("login.");
            window.takeNativeActionWithCallback("login", {
                success: function (res) {
                    console.log("success res: " + JSON.stringify(res))
                    var element = document.createElement("div");
                    element.appendChild(document.createTextNode("userName: " + res.accountName));
                    document.getElementById('login_id').appendChild(element);
                },
                fail: function (res) {
                    console.log("fail res: " + JSON.stringify(res))
                },
                complete: function () {
                    console.log("complete res ")

                }
            });
        }

        function test2() {
            window.takeNativeActionWithCallback("login",
                {
                    targetClassName: "com.xxx222",
                    success: function (res) {
                        console.log("success res: " + JSON.stringify(res))
                        alert("success:登录成功")
                    },
                    fail: function (res) {
                        console.log("fail res: " + JSON.stringify(res))
                    },
                    complete: function () {
                        console.log("complete res ")
                        setTimeout(function () {
                            alert("complete:完成登录")
                        },500)
                    }
                })
        }

        window.onload = function () {
            let btn = document.querySelector('.btn')
            btn.addEventListener('click', function () {
                window.config({debug: true})
                window.test2();
            }, true)

            let callbackBtn = document.querySelector('.callback')
            callbackBtn.addEventListener('click', function () {

                Object.keys(allCallbacks).forEach(function (key) {
                    window.nativetoJsCallback(key, {result:"ok"})
                })


            })

        }


    </script>

</head>
<body>
<p>测试</p>
<button class="btn">点击</button>
<button class="callback">回调</button>

<div id="login_id"></div>

<div>
    <img src="https://img0.baidu.com/it/u=1283434782,3467728248&fm=26&fmt=auto">
</div>
<div>
    <img src="https://img2.baidu.com/it/u=2173052120,291691545&fm=26&fmt=auto">
</div>


</body>


</html>